package study.designpattern.singleton;
/**
 * 
 * @author hawk
 *
 */
public class TestStatic {
	
	private String name;
	//看起来有递归的味道
	//静态变量，只初始化一次，所有的类实例在内存中共享一份拷贝
	private static TestStatic instance = new TestStatic("static");
	
	public static TestStatic getInstance() {
		return instance;
	}
	
	private TestStatic(String name) {
		this.name = name;
	}
	
	public static void main(String[] args) {
		//创建了两个TestSingleton对象，他们拥有相同的属性instance
		TestStatic instance1 = new TestStatic("instance1");
		TestStatic instance2 = new TestStatic("instance2");
		
		System.out.println(instance1+" name="+instance1.name+" instance="+instance1.instance);
		System.out.println(instance2+" name="+instance2.name+" instance="+instance2.instance);
		
		//instance对象的属性
		System.out.println(instance+" instance.name="+instance.name+" instance.instance="+instance.instance);
	}
}
